﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DayNightManager : MonoBehaviour
{
    public Light light;
    public float timeScale;
    public float hour;
    public float min;
    public float sec;
    private float oldt;
    private float t = 43200;
    // Use this for initialization
    void Start()
    {
        light = FindObjectOfType<Light>();
    }

    // Update is called once per frame
    void Update()
    {
        t += Time.deltaTime * timeScale;
        hour = (t / 3600) % 24;
        min = (t / 60) % 60;
        sec = t % 60;
        light.transform.rotation = Quaternion.Euler((t - 21600) / 240, -90, 0);
        if (hour > 6 && hour <= 12) light.intensity = (hour - 6) / 6;
        else if (hour > 12 && hour < 18) light.intensity = (18 - hour) / 6;
        else light.intensity = 0;
        RenderSettings.ambientIntensity = light.intensity;
        //RenderSettings.fogColor = Color.Lerp(Color.black, Color.green, light.intensity);
        
    }
}
